<template>
	<view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e60737;">&#xe611;</text>工号</view>
			<view class="input-content">
				<input class="text-input" type="text" placeholder="请输入您的id" v-model="tid" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #e6c611;">&#xe7fc;</text>奖励名</view>
			<view class="input-content">
				<input class="text-input" type="text" placeholder="请输入奖励名" v-model="name" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #34e614;">&#xe6d9;</text>奖励来源</view>
			<view class="input-content">
				<input class="text-input" type="text" placeholder="请输入奖励来源" v-model="source" />
			</view>
		</view>
		<view class="input-item">
			<view class="title"><text class="iconfont" style="color: #222fe6;">&#xe62a;</text>获得日期</view>
			<view class="input-content">
				<picker mode="date" :value="getTime" @change="getTime=$event.detail.value">
					<view class="uni-input">{{getTime}}</view>
				</picker>
			</view>
		</view>
		<view class="textarea">
			<textarea placeholder="请输入奖励描述" v-model="con" />
			</view>
		
		<view class="bottom">
			<button type="primary" @click="submit"><text class="iconfont" style="color: #FFFFFF;">&#xe64a;</text>提交</button>
		</view>
	</view>
</template>
<script>
	import {rewardEdit} from '@/api/tAchievementMaintenance.js'
	import {delRewardApply} from '@/api/tAchievementApply.js'
	import {getRewardInfo} from '@/api/tAchievementList.js'
	function getDate() {
		const date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		month = month > 9 ? month : '0' + month;;
		day = day > 9 ? day : '0' + day;
		return `${year}-${month}-${day}`;
	}
	export default {
		data() {
			return {
				teaAwardId:'',
				tid:123,
				name:'',
				con:'',
				getTime:getDate(),
				source:'',
				teaAwardChangeId:''
			}
		},
		methods: {
			submit(){
				let data = {
					tid:this.tid,
					teaAwardId:this.teaAwardId,
					name:this.name,
					source:this.source,
					getTime:this.getTime,
					con: this.con,
					teaAwardChangeId:''
				}
				rewardEdit(data).then(res=>{
					if(res.data.code==0){
						uni.showModal({
							content:'提交成功',
							showCancel:false,
							success:()=> {
								delRewardApply({
									teaAwardChangeId:this.teaAwardChangeId
								})
								uni.navigateBack()
							}
						})
					}else{
						uni.showModal({
							content:'提交失败',
							showCancel:false,
						})
					}
				}).catch(err=>{
					uni.showModal({
						content:'网络异常',
						showCancel:false,
					})
				})
			}
		},
		onLoad(option){
			this.teaAwardId=option.teaAwardId
			this.teaAwardChangeId=option.teaAwardChangeId
			uni.showLoading()
			getRewardInfo({
				teaAwardId:option.teaAwardId
			}).then(res=>{
				this.name=res.data.data.name
				this.con=res.data.data.con
				this.getTime=res.data.data.getTime
				this.source=res.data.data.source
				uni.hideLoading()
			})
		}
	}
</script>

<style>
	.iconfont {
		font-family: "iconfont" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		color: #C0C0C0;
		font-size: 16px;
		margin-right: 5px;
	}
	.input-item {
		height: auto;
		position: relative;
		height: 40px;
		margin: 5px 10px;
		border-bottom: 1px solid #C0C0C0;
		font-family: 'Courier New', Courier, monospace;
	}

	.input-item .title {
		position: absolute;
		top: 0;
		left: 0;
		width: 30%;
		height: 100%;
		/* text-align: center; */
		line-height: 40px;
		margin-left: 3px;
	}


	.input-item .input-content {
		position: absolute;
		top: 0;
		right: 0;
		width: 70%;
		height: 100%;
	}

	.input-item .input-content .text-input {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
	picker{
		margin-top: 5px;
	}
	
	.textarea{
		margin-top: 15px;
		padding: 0 10px;
		height: 150px;
	}
	.textarea textarea{
		width: 100%;
		border-radius: 10px;
		border: 1px solid #808080;
		font-family: 'Courier New', Courier, monospace;
	}
	.bottom{
		margin-top: 30px;
		padding: 0 10px;
	}
	
</style>
